/**
 * OpportunityLog实体类
 *
 * @author sxf
 * @email sxf02615@163.com
 * @date 2025/1/15
 */
package com.sxf.crm.entity;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.sxf.crm.enums.OpportunityStatus;
import com.sxf.crm.enums.OpportunityLogOperationType;
import jakarta.persistence.*;
import lombok.Data;
import lombok.Builder;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

/**
 * 商机日志实体类
 *
 * @author sxf
 * @date 2025/6/9
 */
@Data
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "opportunity_logs")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class OpportunityLog {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "opportunity_id", nullable = false)
    private Opportunity opportunity; // 关联的商机

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "operator_id", nullable = false)
    private User operator; // 操作人

    @Enumerated(EnumType.STRING)
    @Column(name = "operation_type", nullable = false)
    private OpportunityLogOperationType operationType; // 操作类型

    @Column(name = "operation_time", nullable = false)
    private Long operationTime; // 操作时间

    @Column(name = "operation_desc", nullable = false)
    private String operationDesc; // 操作描述

    @Enumerated(EnumType.STRING)
    @Column(name = "status_before")
    private OpportunityStatus statusBefore; // 变更前状态

    @Enumerated(EnumType.STRING)
    @Column(name = "status_after") 
    private OpportunityStatus statusAfter; // 变更后状态
    
    @Column(name = "details", length = 1000)
    private String details; // 存储额外的操作细节，JSON格式
}
